package com.zisuyi.uilibrary.module.dialog

import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.FragmentActivity
import com.weilele.mvvm.base.helper.appCompatActivity
import com.zisuyi.game.sdk.utils.UserData
import com.zisuyi.uilibrary.base.BaseUiDialog
import com.zisuyi.uilibrary.databinding.DialogShareBinding
import com.zisuyi.uilibrary.uitils.shareFb
import com.zisuyi.uilibrary.uitils.shareGp
import com.zisuyi.uilibrary.uitils.shareIns
import com.zisuyi.uilibrary.uitils.shareMore

class ShareDialog : BaseUiDialog<DialogShareBinding>() {
    companion object {
        fun show(activity: FragmentActivity) {
            ShareDialog().show(activity)
        }
    }

    private val shareCode: String
        get() {
            return UserData.userInfo?.code ?: ""
        }


    override fun getClickView(): List<View?>? {
        return listOf(
                mBinding.inviteFacebookIv,
                mBinding.inviteInsIv,
                mBinding.inviteGoogleIv,
                mBinding.inviteShareMoreIv,
                mBinding.ivDialogClose
        )
    }

    override fun onSingleClick(view: View) {
        super.onSingleClick(view)
        when (view) {
            mBinding.inviteFacebookIv -> {
                shareFb(appCompatActivity, shareCode)
            }
            mBinding.inviteInsIv -> {
                shareIns(appCompatActivity, shareCode)
            }
            mBinding.inviteGoogleIv -> {
                shareGp(appCompatActivity, shareCode)
            }
            mBinding.inviteShareMoreIv -> {
                shareMore(appCompatActivity, shareCode)
            }
        }
        dismiss()
    }

    override fun isCanceledOnTouchOutside(): Boolean {
        return true
    }


    override fun onRootViewLayoutParams(lp: FrameLayout.LayoutParams) {
        super.onRootViewLayoutParams(lp)
        lp.gravity = Gravity.BOTTOM
        lp.marginStart = 0
        lp.marginEnd = 0
    }
}